﻿using System.Linq;
using Fuse8.ContentManagementFramework.DataAccess.SqlAccess.Mappers;
using Fuse8.ContentManagementFramework.Domain;
using Fuse8.ContentManagementFramework.Domain.Commands;
using Fuse8.ContentManagementFramework.Domain.Special;
using Fuse8.DomainFramework.Common.Locator;
using Fuse8.DomainFramework.DataAccess;
using Fuse8.DomainFramework.DataAccess.SqlDatabase;

namespace Fuse8.ContentManagementFramework.DataAccess.SqlAccess.Commands
{
    internal class CmsContentTypeDeleteDataCommand : CmsContentTypeDeleteCommand
    {
        public override IQueryable<CmsContentType> Execute()
        {
            var factory = DependencyServiceLocator.Current.GetInstance<IUnitOfWorkFactory<CmsContentType>>();

            var currentUnitOfWork = factory.Get(false) as SqlUnitOfWork<CmsContentType>;

            if (currentUnitOfWork != null)
            {
                var mapper = DependencyServiceLocator.Current.GetInstance<ISqlEntityDataMapper<CmsContentType, int>>();
                SqlUtility<CmsContentType, int>.ExecuteNonQuery(
                        currentUnitOfWork.Connection,
                        currentUnitOfWork.Transaction,
                        "cms_sp_ContentTypeDelete",
                        new {Id},
                        mapper,
                       false);
            }

            return null;
        }
    }
}